<template>
    <div>
        <Title :title="title"></Title>
        <div ref="bottom1" style="height: 120px;"></div>
    </div>
</template>
<script>
import { Line } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
export default {
    data() {
        return {
            title: '服务事项概览',
            columnData:[]
        }
    },
    methods: {
        loadColumn() {
            const line = new Line(this.$refs.bottom1, {
                data: this.columnDate,
                xField: 'insert_time',
                yField: 'noise',
                // 配置x轴字段
                xAxis: {
                    label: {
                        style: {
                            fill: 'white'
                        }
                    }
                },
                // 配置y轴字段
                yAxis: {
                    label: {
                        style: {
                            fill: 'white'
                        }
                    }
                },
                label: {
                    style: {
                        fill: 'white'
                    }
                },
                animation: {
                    appear: {
                        animation: 'wave-in',
                        duration: 5000,
                    },
                },
                point: {
                    size: 5,
                    shape: 'diamond',
                    style: {
                        fill: 'white',
                        stroke: '#5B8FF9',
                        lineWidth: 2,
                    },
                },
                tooltip: {
                    showMarkers: false,
                    domStyles: {
                        "g2-tooltip": {
                            background: "#147",
                            color: 'white',
                            fontSize: '20px'

                        }
                    }

                },
                state: {
                    active: {
                        style: {
                            shadowBlur: 4,
                            stroke: '#000',
                            fill: 'red',
                        },
                    },
                },
                interactions: [{ type: 'marker-active' }],
            });

            line.render();
        },
        async getCloumnData(){
            let res = await get('/dashboard/pageQueryTodayData',{page:1,pageSize:100});
            console.log(res,'获取响应');
            let temp = [];
            res.data.list.forEach((item,index,arr)=>{
                // 因为y轴刻度混乱
                arr[0].noise = 52.1;
                item.insert_time = moment(item.insert_time).format('HH:mm:ss');
                // 处理数据 每个10条选取一条数据
                if(index % 10 == 0){
                    temp.push(arr[index]);
                }
            });
            this.columnDate = temp;

        },
    },
    // 生命周期 vue实例与模板绑定完成 此时可以获取dom元素
     async mounted() {
        await this.getCloumnData();
        this.loadColumn();
    },
 
}
</script>
<style lang="" scoped>

</style>